<?php

defined( 'PDNS_CORE' ) or die( "Unauthorized" );

class Config{

	/*
		standard singleton pattern
	*/
	private static $instance;
	
	public static function getInstance(){
		if (!isset(self::$instance)) {
			$c = __CLASS__;
			self::$instance = new $c();
		}
		return self::$instance;
	}
	
	/**
	 *  return a config variable
	 *  @param string name of variable
	 *  @return value
	 */
	public static function get( $name ){
		$config = self::getInstance();
		return $config->$name;
	}

	// realm to require http auth for
	var $auth_realm = 'pdnsFront';

	// debug is on by default, there are no public facing sides of this site anyway, so this is fine.
	var $debug = true;
	
	// db settings
	var $db_host = 'localhost';
	var $db_db = null;
	var $db_prefix = 'pdns_';

	var $noConfig = false;
	
	// enforce https connection
	var $ssl = true;

	function __construct(){
		$config_file = 'config.php';

		// check for config file, if it does not exist, consider pdnsFront to be not installed.
		if( !file_exists( $config_file )){
			$this->noConfig = true;
			return;
		}
		
		include_once( $config_file );

		// here we assign config vars from ../config.php to $this only if those variables were set in ../config.php
		foreach( get_object_vars( $this ) as $n => $v ){
			if( isset( $$n ))
				$this->$n = $$n;
		}
	}
}
